/******FIGURE V: EFFECTS BY DECEASED WEAPON***********/


/*******RUN ANALYSIS**********/
use ../data/main.dta, clear
keep if sample_main==1

global fixed_effects "cb pop_dec#elec_id CBG#elec_id"

foreach x in armed unarmed {
foreach y in reg vote {
	sum `y' if tau==-1 & sample_`x'
	local m = round(r(mean), .01)
	eventdd `y' all if sample_`x', timevar(tau) ///
	absorb( $fixed_effects ) hdfe tolerance(0.0001) cluster(CBG) ///
	ci(rarea) ci_op(fcolor(gs10%30))
	parmest, label saving (../estimates/fig5_`y'_`x', replace) idstr(`y'_`x')
	outreg2 using ../output/table_event.xls, append stats(coef se) ctitle(`y') dec(3) alpha(.01, .05, .10) addtext(killings, `x', mean, `m') symbol(***, **, *) excel side

}
}

/*******CREATE FIGURES*********/

local color1 = "navy"
local color2 = "maroon*0.65"
local symbol1 = "circle"
local symbol2 = "diamond"
local tsize = "large"
local labsize = "medlarge"
local titlesize = "vlarge"

clear
foreach x in unarmed armed {
foreach y in reg vote {
    append using ../estimates/fig5_`y'_`x'
}
}

local lower = -40
local upper = 40
local lower1 = `lower'-2
local upper1 = `upper'+2
local increment = 10

gen time = real(substr(parm, -1, 1))
replace time = time*-1 if strpos(parm, "lag")==0

drop if time==.

expand 2 if time==-2, gen(omit)
replace time = -1 if omit
replace estimate = 0 if omit
replace min95 = 0 if omit
replace max95 = 0 if omit

gen reg = strpos(idstr, "reg")!=0

replace time = time -.15 if reg==1
replace time = time + .15 if reg==0


gen type = "unarmed" if strpos(idstr, "unarmed")>0
replace type = "armed" if type==""

foreach t in unarmed armed {

graph twoway (scatter estimate time if reg, mcolor(`color1') msymbol(`symbol1')) (rcap min95 max95 time if reg, lcolor(`color1')) (scatter estimate time if !reg, mcolor(`color2') msymbol(`symbol2')) (rcap min95 max95 time if !reg, lcolor(`color2')) if type=="`t'", ///
	xline(-.5, lcolor(red)) yline(0, lcolor(gs5)) ///
	ylabel(`lower'(`increment')`upper', grid labsize(`labsize')) yscale(range(`lower1' `upper1')) ///
	xlabel(-4(1)3) xscale(range(-4 3)) ///
	ytitle("Counts", size(`tsize')) ///
	xtitle("Elections to Killing", size(`tsize')) ///
	legend(order(1 3) label(1 "Registrations") label(3 "Votes") size(`tsize')) ///
 plotregion(fcolor(white)) graphregion(fcolor(white) lwidth(large) lcolor(white)) bgcolor(white)
	graph export ../output/fig5_`t'.png, replace
	graph export ../output/fig5_`t'.eps, replace

}

/* Collapse post period into single indicator to generate aggregate point 
estimates for discussion in text */

use ../data/main.dta, clear
keep if sample_main
global fixed_effects "cb pop_dec#elec_id CBG#elec_id"
foreach x in armed unarmed {
di "shooting type: `x'"
foreach y in reg vote {
	di "out: `y' , shooting type: `x'"
	reghdfe `y' treat_post if sample_`x',  absorb( $fixed_effects ) cluster(CBG) nocons
}
}

